package com.yueka.controller;

import com.yueka.pojo.Result;
import com.yueka.pojo.honor.Honor;
import com.yueka.service.HonorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/honor")
@RestController
public class HonorController {

    @Autowired
    private HonorService honorService;

    @GetMapping("/list")
    public Result list() {
        try {
            return Result.success(honorService.list());
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/insert")
    public Result insert(@RequestBody Honor honor) {
        try {
            honorService.insert(honor);
            return Result.success();
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/update")
    public Result update(@RequestBody Honor honor) {
        try {
            honorService.update(honor);
            return Result.success();
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @GetMapping("/delete")
    public Result delete(Integer id) {
        try {
            honorService.delete(id);
            return Result.success();
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

}
